import React from 'react'
import { Redirect, Switch, Route } from 'react-router-dom'
import { shallowEqual, useSelector, useDispatch } from 'react-redux'
import { Layout } from 'antd';

import { deleteUserAction } from '../../store/actionCreators/login'
import './admin.less'
import Header from '../../components/Header/header'
import LeftNav from '../../components/LeftNav/left_nav'

import Home from '../Home/home'
import Category from '../Category/category'
import Product from '../Product/product'
import User from '../User/user'
import Role from '../Role/role'
import Bar from '../Bar/bar'
import Line from '../Line/line'
import Pie from '../Pie/pie'
import Detail from '../Detail/detail'
import Add_Update from '../Add_Update/add_update'


const { Footer, Sider, Content } = Layout;

export default function Login(props) {
  const dispatch = useDispatch()
  const { userInfo, isLogin } = useSelector((state) => ({
    userInfo: state.userInfo.user,
    isLogin: state.userInfo.isLogin
  }), shallowEqual)

  const { username } = userInfo




  return (
    !isLogin ? <Redirect to="/login" /> : (
      <Layout className="admin-root">
        <Sider className="admin-sider">
          <LeftNav />
        </Sider>
        <Layout>
          <Header />
          <Content className="admin-content">
            <Switch>
              <Route path="/admin/home" component={Home} />
              <Route path="/admin/prod_about/category" component={Category} />
              <Route path="/admin/prod_about/product" exact component={Product} />
              <Route path="/admin/prod_about/product/add" component={Add_Update} />
              <Route path="/admin/prod_about/product/update/:id" component={Add_Update} />
              <Route path="/admin/prod_about/product/detail/:id" component={Detail} />
              <Route path="/admin/user" component={User} />
              <Route path="/admin/role" component={Role} />
              <Route path="/admin/charts/bar" component={Bar} />
              <Route path="/admin/charts/line" component={Line} />
              <Route path="/admin/charts/pie" component={Pie} />
              <Redirect to="/admin/home" />
            </Switch>
          </Content>
          <Footer className="admin-footer">推荐使用谷歌浏览器，获取最佳用户体验</Footer>
        </Layout>
      </Layout>
    )
  )
}